#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
int tr[N][26], sz[N], tot;
int newnode() { return ++tot; }
void insert(string s) {
  int p = 0;
  for (char c : s) {
    int x = c - 'a';
    if (!tr[p][x]) tr[p][x] = newnode();
    p = tr[p][x];
  }
  sz[p] = 1;
}
int search(string s) {
  int p = 0;
  for (char c : s) {
    int x = c - 'a';
    if (!tr[p][x]) return 0;
    p = tr[p][x];
  }
  if (sz[p] == 1) {
    sz[p] = -1;
    return 1;
  } else
    return sz[p];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) {
    string s;
    cin >> s;
    insert(s);
  }
  cin >> n;
  rep(i, 1, n) {
    string s;
    cin >> s;
    int res = search(s);
    if (res == 1)
      cout << "OK\n";
    else if (res == -1)
      cout << "REPEAT\n";
    else
      cout << "WRONG\n";
  }
  return 0;
}